(0) Obligation:

The Runtime Complexity (innermost) of the given CpxTRS could be proven to be BOUNDS(1, 1).


The TRS R consists of the following rules:

f(x, y, z) → g(<=(x, y), x, y, z)
g(true, x, y, z) → z
g(false, x, y, z) → f(f(p(x), y, z), f(p(y), z, x), f(p(z), x, y))
p(0) → 0
p(s(x)) → x

Rewrite Strategy: INNERMOST

(1) TrsToWeightedTrsProof (BOTH BOUNDS(ID, ID) transformation)

Transformed TRS to weighted TRS

(2) Obligation:

The Runtime Complexity (innermost) of the given CpxWeightedTrs could be proven to be BOUNDS(1, 1).


The TRS R consists of the following rules:

f(x, y, z) → g(<=(x, y), x, y, z) [1]
g(true, x, y, z) → z [1]
g(false, x, y, z) → f(f(p(x), y, z), f(p(y), z, x), f(p(z), x, y)) [1]
p(0) → 0 [1]
p(s(x)) → x [1]

Rewrite Strategy: INNERMOST

(3) TypeInferenceProof (BOTH BOUNDS(ID, ID) transformation)

Infered types.

(4) Obligation:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

f(x, y, z) → g(<=(x, y), x, y, z) [1]
g(true, x, y, z) → z [1]
g(false, x, y, z) → f(f(p(x), y, z), f(p(y), z, x), f(p(z), x, y)) [1]
p(0) → 0 [1]
p(s(x)) → x [1]

The TRS has the following type information:
f :: 0:s → 0:s → 0:s → 0:s
g :: <=:true:false → 0:s → 0:s → 0:s → 0:s
<= :: 0:s → 0:s → <=:true:false
true :: <=:true:false
false :: <=:true:false
p :: 0:s → 0:s
0 :: 0:s
s :: 0:s → 0:s

Rewrite Strategy: INNERMOST

(5) CompletionProof (UPPER BOUND(ID) transformation)

The TRS is a completely defined constructor system, as every type has a constant constructor and the following rules were added:

g(v0, v1, v2, v3) → null_g [0]
p(v0) → null_p [0]

And the following fresh constants:

null_g, null_p

(6) Obligation:

Runtime Complexity Weighted TRS where all functions are completely defined. The underlying TRS is:

Runtime Complexity Weighted TRS with Types.
The TRS R consists of the following rules:

f(x, y, z) → g(<=(x, y), x, y, z) [1]
g(true, x, y, z) → z [1]
g(false, x, y, z) → f(f(p(x), y, z), f(p(y), z, x), f(p(z), x, y)) [1]
p(0) → 0 [1]
p(s(x)) → x [1]
g(v0, v1, v2, v3) → null_g [0]
p(v0) → null_p [0]

The TRS has the following type information:
f :: 0:s:null_g:null_p → 0:s:null_g:null_p → 0:s:null_g:null_p → 0:s:null_g:null_p
g :: <=:true:false → 0:s:null_g:null_p → 0:s:null_g:null_p → 0:s:null_g:null_p → 0:s:null_g:null_p
<= :: 0:s:null_g:null_p → 0:s:null_g:null_p → <=:true:false
true :: <=:true:false
false :: <=:true:false
p :: 0:s:null_g:null_p → 0:s:null_g:null_p
0 :: 0:s:null_g:null_p
s :: 0:s:null_g:null_p → 0:s:null_g:null_p
null_g :: 0:s:null_g:null_p
null_p :: 0:s:null_g:null_p

Rewrite Strategy: INNERMOST

(7) CpxTypedWeightedTrsToRntsProof (UPPER BOUND(ID) transformation)

Transformed the TRS into an over-approximating RNTS by (improved) Size Abstraction.
The constant constructors are abstracted as follows:

true => 1
false => 0
0 => 0
null_g => 0
null_p => 0

(8) Obligation:

Complexity RNTS consisting of the following rules:

f(z', z'', z1) -{ 1 }→ g(1 + x + y, x, y, z) :|: z1 = z, z >= 0, z' = x, z'' = y, x >= 0, y >= 0
g(z', z'', z1, z2) -{ 1 }→ z :|: z1 = y, z >= 0, z2 = z, x >= 0, y >= 0, z'' = x, z' = 1
g(z', z'', z1, z2) -{ 1 }→ f(f(p(x), y, z), f(p(y), z, x), f(p(z), x, y)) :|: z1 = y, z >= 0, z2 = z, x >= 0, y >= 0, z'' = x, z' = 0
g(z', z'', z1, z2) -{ 0 }→ 0 :|: z2 = v3, v0 >= 0, z1 = v2, v1 >= 0, z'' = v1, v2 >= 0, v3 >= 0, z' = v0
p(z') -{ 1 }→ x :|: z' = 1 + x, x >= 0
p(z') -{ 1 }→ 0 :|: z' = 0
p(z') -{ 0 }→ 0 :|: v0 >= 0, z' = v0

Only complete derivations are relevant for the runtime complexity.

(9) CompleteCoflocoProof (EQUIVALENT transformation)

Transformed the RNTS (where only complete derivations are relevant) into cost relations for CoFloCo:

eq(start(V, V1, V2, V6),0,[f(V, V1, V2, Out)],[V >= 0,V1 >= 0,V2 >= 0]).
eq(start(V, V1, V2, V6),0,[g(V, V1, V2, V6, Out)],[V >= 0,V1 >= 0,V2 >= 0,V6 >= 0]).
eq(start(V, V1, V2, V6),0,[p(V, Out)],[V >= 0]).
eq(f(V, V1, V2, Out),1,[g(1 + V3 + V4, V3, V4, V5, Ret)],[Out = Ret,V2 = V5,V5 >= 0,V = V3,V1 = V4,V3 >= 0,V4 >= 0]).
eq(g(V, V1, V2, V6, Out),1,[],[Out = V7,V2 = V8,V7 >= 0,V6 = V7,V9 >= 0,V8 >= 0,V1 = V9,V = 1]).
eq(g(V, V1, V2, V6, Out),1,[p(V10, Ret00),f(Ret00, V11, V12, Ret0),p(V11, Ret10),f(Ret10, V12, V10, Ret1),p(V12, Ret20),f(Ret20, V10, V11, Ret2),f(Ret0, Ret1, Ret2, Ret3)],[Out = Ret3,V2 = V11,V12 >= 0,V6 = V12,V10 >= 0,V11 >= 0,V1 = V10,V = 0]).
eq(p(V, Out),1,[],[Out = 0,V = 0]).
eq(p(V, Out),1,[],[Out = V13,V = 1 + V13,V13 >= 0]).
eq(g(V, V1, V2, V6, Out),0,[],[Out = 0,V6 = V14,V15 >= 0,V2 = V16,V17 >= 0,V1 = V17,V16 >= 0,V14 >= 0,V = V15]).
eq(p(V, Out),0,[],[Out = 0,V18 >= 0,V = V18]).
input_output_vars(f(V,V1,V2,Out),[V,V1,V2],[Out]).
input_output_vars(g(V,V1,V2,V6,Out),[V,V1,V2,V6],[Out]).
input_output_vars(p(V,Out),[V],[Out]).

CoFloCo proof output:
Preprocessing Cost Relations
=====================================

#### Computed strongly connected components
0. non_recursive : [p/2]
1. recursive [non_tail,multiple] : [f/4,g/5]
2. non_recursive : [start/4]

#### Obtained direct recursion through partial evaluation
0. SCC is partially evaluated into p/2
1. SCC is partially evaluated into f/4
2. SCC is partially evaluated into start/4

Control-Flow Refinement of Cost Relations
=====================================

### Specialization of cost equations p/2
* CE 8 is refined into CE [12]
* CE 7 is refined into CE [13]
* CE 9 is refined into CE [14]


### Cost equations --> "Loop" of p/2
* CEs [12] --> Loop 7
* CEs [13,14] --> Loop 8

### Ranking functions of CR p(V,Out)

#### Partial ranking functions of CR p(V,Out)


### Specialization of cost equations f/4
* CE 10 is refined into CE [15]
* CE 11 is refined into CE [16]


### Cost equations --> "Loop" of f/4
* CEs [15] --> Loop 9
* CEs [16] --> Loop 10

### Ranking functions of CR f(V,V1,V2,Out)

#### Partial ranking functions of CR f(V,V1,V2,Out)


### Specialization of cost equations start/4
* CE 4 is refined into CE [17]
* CE 2 is refined into CE [18]
* CE 3 is refined into CE [19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66]
* CE 5 is refined into CE [67,68]
* CE 6 is refined into CE [69,70]


### Cost equations --> "Loop" of start/4
* CEs [17] --> Loop 11
* CEs [44,62] --> Loop 12
* CEs [22,25] --> Loop 13
* CEs [26,28,53,54,55,56] --> Loop 14
* CEs [29,30,31,32,41,42,43,57] --> Loop 15
* CEs [27,35,36,37,38,39,40,47,48,49,50,51,52,58,59,60,61,63,64,65,66] --> Loop 16
* CEs [18,19,20,21,23,24,33,34,45,46,67,68,69,70] --> Loop 17

### Ranking functions of CR start(V,V1,V2,V6)

#### Partial ranking functions of CR start(V,V1,V2,V6)


Computing Bounds
=====================================

#### Cost of chains of p(V,Out):
* Chain [8]: 1
with precondition: [Out=0,V>=0]

* Chain [7]: 1
with precondition: [V=Out+1,V>=1]


#### Cost of chains of f(V,V1,V2,Out):
* Chain [10]: 2
with precondition: [V=0,V1=0,V2=Out,V2>=0]

* Chain [9]: 1
with precondition: [Out=0,V>=0,V1>=0,V2>=0]


#### Cost of chains of start(V,V1,V2,V6):
* Chain [17]: 12
with precondition: [V>=0]

* Chain [16]: 10
with precondition: [V=0,V1>=0,V2>=0,V6>=0]

* Chain [15]: 11
with precondition: [V=0,V6=0,V1>=0,V2>=0]

* Chain [14]: 10
with precondition: [V=0,V2=0,V1>=0,V6>=0]

* Chain [13]: 10
with precondition: [V=0,V2=0,V6=0,V1>=0]

* Chain [12]: 9
with precondition: [V=0,V2=1,V6=0,V1>=0]

* Chain [11]: 1
with precondition: [V=1,V1>=0,V2>=0,V6>=0]


Closed-form bounds of start(V,V1,V2,V6):
-------------------------------------
* Chain [17] with precondition: [V>=0]
- Upper bound: 12
- Complexity: constant
* Chain [16] with precondition: [V=0,V1>=0,V2>=0,V6>=0]
- Upper bound: 10
- Complexity: constant
* Chain [15] with precondition: [V=0,V6=0,V1>=0,V2>=0]
- Upper bound: 11
- Complexity: constant
* Chain [14] with precondition: [V=0,V2=0,V1>=0,V6>=0]
- Upper bound: 10
- Complexity: constant
* Chain [13] with precondition: [V=0,V2=0,V6=0,V1>=0]
- Upper bound: 10
- Complexity: constant
* Chain [12] with precondition: [V=0,V2=1,V6=0,V1>=0]
- Upper bound: 9
- Complexity: constant
* Chain [11] with precondition: [V=1,V1>=0,V2>=0,V6>=0]
- Upper bound: 1
- Complexity: constant

### Maximum cost of start(V,V1,V2,V6): 12
Asymptotic class: constant
* Total analysis performed in 489 ms.

(10) BOUNDS(1, 1)